import os
import sys
import time
import json
import django
import uuid

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")
django.setup()

from core.wchat.mini_base import wechat_client, wechat_client_howhow
from core.tools.oss_upload import oss_upload_file
from core.wchat.wx_base import mc


# 随机券
def make_mini_code(share_id, page="pages/ling/ling"):
    data = {"c_type": 2, "num": 1, "type": "suijiquan", "share_id": share_id}
    params = json.dumps(data)
    key = uuid.uuid1().hex
    mc.set(key, params)
    response = wechat_client.wxa.get_wxa_code_unlimited(key, page=page)
    url = oss_upload_file(response.content)
    print(f"{share_id}       {url}")

def make_mini_code_howho(share_id, page="pages/ling/ling"):
    data = {"c_type": 2, "num": 1, "type": "suijiquan", "share_id": share_id}
    params = json.dumps(data)
    key = uuid.uuid1().hex
    mc.set(key, params)
    response = wechat_client_howhow.wxa.get_wxa_code_unlimited(key, page=page)
    url = oss_upload_file(response.content)
    print(f"{share_id}       {url}")



if __name__ == '__main__':
    share_id_list = [84]
    for i in share_id_list:
        make_mini_code(i)
